Date.prototype.format = function(fmt) {
    var o = {
        'm+': this.getMonth() + 1 + "",
        'd+': this.getDate() + "",
        'h+': this.getHours() + "",
        'M+': this.getMinutes() + "",
        's+': this.getSeconds() + ""
    };

    var ptnYear = /(y+)/;
    if (ptnYear.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, this.getFullYear() + "");
    }

    for (var k in o) {
        var regExp = new RegExp("(" + k + ")");
        console.log(regExp.toString());
        if (regExp.test(fmt)) {
            fmt = fmt.replace(RegExp.$1, o[k]);
        }
    }
    return fmt;
}

var now = new Date();
console.log(now.format('yyyy-mm-dd'));
console.log(now.format('yyyy---mm---dd'))